Skip to content

Conversation

@cxa
Copy link

@cxa cxa commented Nov 19, 2025

This PR prevents the root path "/" from being emptied by removeTrailingSlash.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved handling of trailing slashes in layout-type routes to correctly exclude the root path from trailing-slash removal.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

The trailing-slash removal logic for layout-type route nodes is refined to preserve the root path. The condition now excludes removing trailing slashes when the cleaned path is '/'. The pathless_layout case handling remains unaffected.

Changes

Cohort / File(s) Summary
Layout Route Node Trailing-Slash Fix
packages/router-generator/src/generator.ts
Tightened trailing-slash removal condition for layout-type nodes to exclude root path ('/'). Checks that cleanedPath is not '/' before removing trailing slashes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • Verify the condition logic is correct and the root path '/' is properly excluded
  • Confirm no unintended side effects on layout node path handling

Possibly related PRs

Suggested reviewers

  • schiller-manuel

Poem

🐰 A path trimmed with care,
Root "/" left standing there,
Layout nodes now right—
No slashes to fight! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main fix: preventing the root path from being removed, which matches the core change made to the route generator logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f28edc8 and 6bc7f5b.

📒 Files selected for processing (1)
  • packages/router-generator/src/generator.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/router-generator/src/generator.ts

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cxa cxa force-pushed the route-generator/dont-remove-trailing-slash-for-root branch from 8c6dcea to 07cf53c Compare November 19, 2025 08:33
@cxa cxa changed the title fix: prevent the root path "/" from being removed Prevent the root path "/" from being removed Nov 19, 2025
@nx-cloud
Copy link

nx-cloud bot commented Nov 19, 2025

View your CI Pipeline Execution ↗ for commit f28edc8

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 7m 27s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 32s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-21 02:24:25 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 19, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5899

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5899

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5899

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5899

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5899

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5899

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5899

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5899

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5899

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5899

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5899

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5899

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5899

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5899

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5899

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5899

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5899

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5899

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5899

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5899

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5899

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5899

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5899

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5899

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5899

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5899

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5899

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5899

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5899

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5899

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5899

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5899

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5899

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5899

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5899

commit: f28edc8

@birkskyum
Copy link
Member

@cxa there's a failing unit test that needs some attention.

@schiller-manuel
Copy link
Contributor

first of all we need to understand why this fix is needed. when would this occur?

@cxa cxa force-pushed the route-generator/dont-remove-trailing-slash-for-root branch from 07cf53c to e6bf332 Compare November 20, 2025 05:58
@cxa
Copy link
Author

cxa commented Nov 20, 2025

first of all we need to understand why this fix is needed. when would this occur?

Without this fix, file route like _auth.index/route.tsx will generate a wrong path: '' route instead of the correct path: '/' one. (Since route.tsx is treated as layout, maybe we should use a new FsRouteType for it?)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
e2e/solid-start/basic-cloudflare/worker-configuration.d.ts (1)

10-14: StringifyValues change is sound; note behavior for union/optional envs

The new StringifyValues preserves literal string types and string unions while coercing non‑string values to string, which matches env semantics. Just be aware that fields typed as unions including non‑string members (e.g. string | undefined or number | string) will still be widened to string, so this only narrows fully string-typed bindings. That’s fine for this test, but worth keeping in mind if you later add richer Env typings.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6bf332 and f28edc8.

📒 Files selected for processing (1)
  • e2e/solid-start/basic-cloudflare/worker-configuration.d.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: nlynzaad
Repo: TanStack/router PR: 5182
File: e2e/react-router/basic-file-based/src/routes/non-nested/named/$baz_.bar.tsx:3-5
Timestamp: 2025-09-22T00:56:49.237Z
Learning: In TanStack Router, underscores are intentionally stripped from route segments (e.g., `$baz_` becomes `baz` in generated types) but should be preserved in base path segments. This is the correct behavior as of the fix in PR #5182.
Learnt from: schiller-manuel
Repo: TanStack/router PR: 5330
File: packages/router-core/src/router.ts:2231-2245
Timestamp: 2025-10-01T18:30:26.591Z
Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.
Learnt from: nlynzaad
Repo: TanStack/router PR: 5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.
Learnt from: nlynzaad
Repo: TanStack/router PR: 5182
File: e2e/react-router/basic-file-based/tests/non-nested-paths.spec.ts:167-172
Timestamp: 2025-09-22T00:56:53.426Z
Learning: In TanStack Router, underscores are intentionally stripped from route segments during path parsing, but preserved in base path segments. This is the expected behavior implemented in PR #5182.
Learnt from: schiller-manuel
Repo: TanStack/router PR: 5330
File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61
Timestamp: 2025-10-01T18:31:35.420Z
Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.
🔇 Additional comments (1)
e2e/solid-start/basic-cloudflare/worker-configuration.d.ts (1)

5-7: Env ⇄ ProcessEnv wiring for MY_VAR looks correct

Typing Cloudflare.Env.MY_VAR as the literal 'Hello from Cloudflare' and threading it through NodeJS.ProcessEnv via StringifyValues<Pick<Cloudflare.Env, 'MY_VAR'>> will correctly narrow process.env.MY_VAR in this fixture. No issues from a types or merging perspective.

Also applies to: 16-18

@cxa cxa force-pushed the route-generator/dont-remove-trailing-slash-for-root branch from f28edc8 to 6bc7f5b Compare November 21, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants